<!-- 
 * 科技成果管理
 * @author: 冯宇
 * @since: 2022-05-16
 * index.vue
-->
<template>
  <div class="achievement-container h100">
    <router-view v-show="routerCutLevel === 3" class="detailsPage"></router-view>
    <div v-show="routerCutLevel === 2" class="listPage">
      <Filters :formModel="data.formModel" :formLabel="data.formLabel" @reset="resizeForm" @filter="getAchievementList">
      </Filters>

      <TableCom :tableHeader="data.tableHeader" :tableData="data.tableData" @getCurrentChange="getCurrentChange"
        @getSizeChange="getSizeChange" @comEvent="comEvent" @getSelectChange="getSelectChange" :isShowCheckbox="true"
        @colSelect="colSelect" @refresh="refreshTable" :pagination="data.pagination" :loading="data.loading"
        handleWidth="340" :isShowGrooveHandleCol="false" :isShowLogicHandleCol="true">
        <el-button v-for="(item, index) in data.btnList" :key="index" class="tableBtnCss"
          :style="{ backgroundColor: item.bgColor }" @click="userManageBtnList(index)">
          <svg-icon :name="item.icon" v-if="item.icon"></svg-icon>
          {{ item.name }}
        </el-button>
        <template #handle="scope">
          <div class="table-button">
            <div class="btn" @click="addResultInfo(scope.row.id)" style="color: #2e92fa"
              v-if="!scope.row.assessInnovate && scope.row.isConsole">补充成果信息</div>
            <div class="btn" @click="checkRow(scope.row)" style="color: #ffb018"
              v-if="scope.row.resultState === 'NOT_AUDIT' && scope.row.isConsole === false">审核</div>
            <div class="btn" @click="editRow(scope.row)" :style="{ color: scope.row.valid ? '#D4DBEC' : '#25D390' }"
              @mouseenter="mouseStatus(scope.row, $event)"
              v-if="scope.row.isConsole === true || (scope.row.resultState !== 'NOT_AUDIT' && scope.row.resultState !== 'JOIN' && scope.row.resultState === 'JOIN_OK')">
              编辑</div>
            <div class="btn" @click="operateRow(scope.row, 'del')" style="color: #f74b33">删除</div>
            <div class="btn" v-if="scope.row.resultState != 'NOT_AUDIT'">
              <div class="text-left">是否启用</div>
              <el-switch v-model="scope.row.valid" @change="operateRow(scope.row, 'valid')" />
            </div>
            <div class="btn" v-if="scope.row.resultState != 'NOT_AUDIT'">
              <div class="text-left">是否热门</div>
              <el-switch v-model="scope.row.isHot" @change="hotRow(scope.row)" />
            </div>
          </div>
        </template>
      </TableCom>

      <!-- 上传文件 -->
      <el-dialog v-model="isShowLead" title="批量导入科技成果" width="30%">
        <uploadDownload ref="filedom" @upload="uploadFile" @downloadTemp="downloadFile"></uploadDownload>
      </el-dialog>

      <!-- 成果信息补充 -->
      <div class="add-info-dialog">
        <el-dialog v-model="data.dialogVisible" width="1000px" align-center>
          <template #title>
            <div class="df dialog-title">
              <h3>成果信息补充</h3>
              <span class="tip">补充填写以下成果信息有助于提高成果的可信度，增加匹配成功的几率</span>
            </div>
          </template>

          <template #default>
            <div class="dialog-table">
              <div class="dialog-head df ac pd20">创新性指标</div>

              <el-form :model="data.form" label-position="left">
                <el-form-item label="成果创新程度：">
                  <el-radio v-model="data.form.assessInnovate" label="重大创新">重大创新</el-radio>
                  <el-radio v-model="data.form.assessInnovate" label="明显创新">明显创新</el-radio>
                  <el-radio v-model="data.form.assessInnovate" label="一般创新">一般创新</el-radio>
                </el-form-item>
                <el-form-item label="成果先进性：">
                  <el-radio v-model="data.form.assessAdvanced" label="领先">领先</el-radio>
                  <el-radio v-model="data.form.assessAdvanced" label="先进">先进</el-radio>
                  <el-radio v-model="data.form.assessAdvanced" label="一般">一般</el-radio>
                </el-form-item>
                <el-form-item label="成果创新复杂程度：">
                  <el-radio v-model="data.form.assessComplex" label="自主创新">自主创新</el-radio>
                  <el-radio v-model="data.form.assessComplex" label="引进创新">引进创新</el-radio>
                  <el-radio v-model="data.form.assessComplex" label="技改">技改</el-radio>
                </el-form-item>
              </el-form>
            </div>
            <div class="dialog-table">
              <div class="dialog-head df ac pd20">转化性指标</div>
              <el-form :model="data.form" label-position="left">
                <el-form-item label="是否有样品或样机：">
                  <el-radio v-model="data.form.assessSample" :label="true">含样品或样机</el-radio>
                  <el-radio v-model="data.form.assessSample" :label="false">不含样品或样机</el-radio>
                </el-form-item>
                <el-form-item label="是否有评估报告：">
                  <el-radio v-model="data.form.assessReport" :label="true">含评估报告</el-radio>
                  <el-radio v-model="data.form.assessReport" :label="false">不含评估报告</el-radio>
                </el-form-item>
                <el-form-item label="科研项目资助情况：">
                  <el-radio v-model="data.form.assessSubsidize" label="国家级">国家级</el-radio>
                  <el-radio v-model="data.form.assessSubsidize" label="省部级">省部级</el-radio>
                  <el-radio v-model="data.form.assessSubsidize" label="市级">市级</el-radio>
                  <el-radio v-model="data.form.assessSubsidize" label="其它">其它
                  </el-radio>
                </el-form-item>
                <el-form-item label="成果获奖情况：">
                  <el-radio v-model="data.form.assessAward" label="国家级">国家级</el-radio>
                  <el-radio v-model="data.form.assessAward" label="省部级">省部级</el-radio>
                  <el-radio v-model="data.form.assessAward" label="市级">市级</el-radio>
                  <el-radio v-model="data.form.assessAward" label="其它">其它 </el-radio>
                </el-form-item>
                <el-form-item label="是否已经产生经济效益：">
                  <el-radio v-model="data.form.assessIsEconomicBenefits" :label="false">否</el-radio>
                  <el-radio v-model="data.form.assessIsEconomicBenefits" :label="true">是 &emsp;<span>已产生经济效益：</span>
                    <el-input style="width: 200px" size="mini" v-model="data.form.assessEconomicBenefits"
                      placeholder="请输入经济效益" />
                  </el-radio>
                </el-form-item>
                <el-form-item label="社会效益：">
                  <el-radio v-model="data.form.assessSocialBenefits" label="显著">显著</el-radio>
                  <el-radio v-model="data.form.assessSocialBenefits" label="明显">明显</el-radio>
                  <el-radio v-model="data.form.assessSocialBenefits" label="一般">一般</el-radio>
                </el-form-item>
                <el-form-item label="应用效果：">
                  <el-radio v-model="data.form.assessApplicationEffect" label="国际优势">国际优势</el-radio>
                  <el-radio v-model="data.form.assessApplicationEffect" label="国内优势">国内优势</el-radio>
                  <el-radio v-model="data.form.assessApplicationEffect" label="一定需求">一定需求</el-radio>
                </el-form-item>
              </el-form>
            </div>
            <div class="dialog-table">
              <div class="dialog-head df ac pd20">研发性指标</div>
              <el-form :model="data.form" label-position="left">
                <el-form-item label="研发投入：">
                  <el-radio v-model="data.form.assessInputMoney" :label="1">100万以下</el-radio>
                  <el-radio v-model="data.form.assessInputMoney" :label="2">100万~200万</el-radio>
                  <el-radio v-model="data.form.assessInputMoney" :label="3">200万~500万</el-radio>
                  <el-radio v-model="data.form.assessInputMoney" :label="4">500万以上</el-radio>
                </el-form-item>
              </el-form>
            </div>
          </template>

          <template #footer>
            <div class="dialog-footer">
              <el-button @click="data.dialogVisible = false" size="large">取 消</el-button>
              <el-button type="primary" @click="addInfo" size="large">确 定</el-button>
            </div>
          </template>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, computed, ref } from 'vue'
import { getDictListApi, getDictItemListApi, getDomainApi, getRegionApi } from '@/api/public/publicDict.js'
import { getAchievementListApi, achievementDetailApi, editAchievementApi, operateAchievementApi } from '@/api/interface/achievement.js'
import { colFilters, batchHandle, lineHandle, fileDownload } from '@/utils/common.js'
import { uploadOtherFileApi, dowloadOtherFileApi } from '@/api/public/uploadFile.js'

import { ElMessageBox, ElMessage } from 'element-plus'

import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
const router = useRouter()
const store = useStore()
const isShowLead = ref(false)
const filedom = ref(null)


const routerCutLevel = computed(() => {
  return store.getters['setting/routerCutLevel']
})

const data = reactive({
  formModel: {
    achieveName: '',
    field: '',
    achieveType: '',
    provinceCode: '',
    mature: '',
    cooperation: '',
    amountMoney: '',
    includePatent: '',
    date: '',
    isHot: '',
    valid: '',
    isConsole: '',
  },
  formLabel: [
    {
      label: '成果名称',
      model: "achieveName",
      type: "text",
      width: '160',
      placeholder: '请输入成果名称',
    },
    {
      label: '成果所属领域',
      model: "field",
      type: "select",
      width: '160',
      option: [
        {
          key: '全部',
          value: ''
        },
      ],
    },
    {
      label: '成果类型',
      model: "achieveType",
      type: "select",
      width: '160',
      option: [
        {
          key: '全部',
          value: ''
        },
      ],
    },
    {
      label: '成果所在地',
      model: "provinceCode",
      type: "select",
      width: '160',
      option: [
        {
          key: '全部',
          value: ''
        },
      ],
    },
    {
      label: '技术成熟度',
      model: "mature",
      type: "select",
      width: '160',
      option: [
        {
          key: '全部',
          value: ''
        },
      ],
    },
    {
      label: '合作方式',
      model: "cooperation",
      type: "select",
      width: '160',
      option: [
        {
          key: '全部',
          value: ''
        },
      ],
    },
    {
      label: '合作金额（万元）',
      model: "amountMoney",
      type: "select",
      width: '160',
      option: [
        {
          key: '全部',
          value: ''
        },
      ],
    },
    {
      label: '是否含专利',
      model: "includePatent",
      type: "select",
      width: '160',
      option: [
        {
          key: '全部',
          value: ''
        },
        {
          key: '含专利',
          value: true
        },
        {
          key: '不含专利',
          value: false
        },
      ],
    },
    {
      label: '是否后台发布',
      model: "isConsole",
      type: "select",
      width: '160',
      option: [
        {
          key: '全部',
          value: ''
        },
        {
          key: '是',
          value: true
        },
        {
          key: '否',
          value: false
        },
      ],
    },
    {
      label: '是否启用',
      model: "valid",
      type: "select",
      width: '160',
      option: [
        {
          key: '全部',
          value: ''
        },
        {
          key: '启用',
          value: true
        },
        {
          key: '禁用',
          value: false
        },
      ],
    },
    {
      label: '是否热门',
      model: "isHot",
      type: "select",
      width: '160',
      option: [
        {
          key: '全部',
          value: ''
        },
        {
          key: '是',
          value: true
        },
        {
          key: '否',
          value: false
        },
      ],
    },
    {
      label: '成果截止时间',
      model: "date",
      type: "dateRange",
      width: '360',
      option: [],
    },
  ],
  btnList: [
    {
      name: '新增科技成果',
      bgColor: '#25D390',
    },
    {
      name: '成果导入',
      bgColor: '#00A2FF',
    },
    {
      name: '批量启用',
      bgColor: '#00A2FF',
    },
    {
      name: '批量禁用',
      bgColor: '#FFB018',
    },
    {
      name: '批量删除',
      bgColor: '#F74B33',
    },
  ],
  tableHeader: [
    {
      label: '成果名称',
      prop: 'resultTitle',
      isLink: true,
      function: 'detail'
    },
    {
      label: '所属领域',
      prop: 'industryNameOne',
    },
    {
      label: '成果类型',
      prop: 'resultTypeName',
    },
    {
      label: '成果所在地',
      prop: 'resultProvinceName',
    },
    {
      label: '截止时间',
      prop: 'resultExpirationDate',
    },
    {
      label: '合作方式',
      prop: 'resultCooperationName',
    },
    {
      label: '合作金额(万元)',
      prop: 'resultBudget',
    },
    {
      label: '技术成熟度',
      prop: 'resultSkillStageName',
    },
    {
      label: '是否含专利',
      prop: 'patent',
    },
    {
      label: '审核状态',
      prop: 'resultStateName',
    }
  ],
  tableData: [],
  currentSelectList: [],
  pagination: {
    currentPage: 1,
    size: 10,
    total: 0,
  },
  loading: false,

  dialogVisible: false,
  radio: '1',
  form: {
    assessInnovate: '',
    assessAdvanced: '',
    assessComplex: '',
    assessSample: null,
    assessReport: null,
    assessSubsidize: '',
    assessAward: '',

    assessIsEconomicBenefits: null,
    assessEconomicBenefits: '',

    assessSocialBenefits: '',
    assessApplicationEffect: '',
    assessInputMoney: null,
  },
  currentResultDetail: {}
})

//获取科技成果列表
const getAchievementList = () => {
  data.loading = true;
  const params = {
    orderField: "publishDate",
    orderType: 'desc',
    endDate: data.formModel.date ? data.formModel.date[1] : '',
    includePatent: data.formModel.includePatent,
    ipi: data.pagination.currentPage,
    ips: data.pagination.size,
    isHot: data.formModel.isHot,
    keyword: data.formModel.achieveName,
    resultAreaCode: '',
    resultBudgetCode: data.formModel.amountMoney,
    resultCityCode: '',
    resultCodeOne: data.formModel.field,
    resultCooperationCode: data.formModel.cooperation,
    resultProvinceCode: data.formModel.provinceCode,
    resultSkillStageCode: data.formModel.mature,
    resultTypeId: data.formModel.achieveType,
    startDate: data.formModel.date ? data.formModel.date[0] : '',
    valid: data.formModel.valid,
    isConsole: data.formModel.isConsole,
  }
  getAchievementListApi(JSON.stringify(params)).then((res) => {
    if (res.status === 200) {
      const arr = res.data.result.map(v => {
        v.patent = v.includePatent ? '含专利' : '不含专利';
        return v
      })
      data.tableData = arr
      data.loading = false
      data.pagination.total = res.data.total
    }
  })
}
getAchievementList()
//重置搜索条件
const resizeForm = () => {
  for (let key in data.formModel) {
    if (typeof data.formModel[key] == 'string') {
      data.formModel[key] = ''
    } else {
      data.formModel[key] = []
    }
  }
  getAchievementList()
}




//获取字典项 / 成果类型  /  技术成熟度  / 合作方式  /  合作金额
const getDictList = async () => {
  const dict = {
    ipi: 1,
    ips: 20,
    keyName: '',
  }
  const dictList = await getDictListApi(dict).then((res) => {
    if (res.status === 200) {
      return res.data.result
    }
  })
  dictList.forEach((v) => {
    if (v.keyId === 'DICT_RESULT_COOPERATION') {
      let a = {
        dictType: v.keyId,
      }
      getDictItemListApi(JSON.stringify(a)).then((res) => {
        if (res.status === 200) {
          let arr = res.data.result.map(v => ({
            key: v.keyName,
            value: v.keyId
          }))

          for (let v of data.formLabel) {
            if (v.model == 'cooperation') {
              v.option = [...v.option, ...arr]
              break
            }
          }
        }
      })
    } else if (v.keyId === 'DICT_RESULT') {
      let a = {
        dictType: v.keyId,
      }
      getDictItemListApi(JSON.stringify(a)).then((res) => {
        if (res.status === 200) {
          let arr = res.data.result.map(v => ({
            key: v.keyName,
            value: v.keyId
          }))

          for (let v of data.formLabel) {
            if (v.model == 'achieveType') {
              v.option = [...v.option, ...arr]
              break
            }
          }
        }
      })
    } else if (v.keyId === 'DICT_SKILL_STAGE') {
      let a = {
        dictType: v.keyId,
      }
      getDictItemListApi(JSON.stringify(a)).then((res) => {
        if (res.status === 200) {
          let arr = res.data.result.map(v => ({
            key: v.keyName,
            value: v.keyId
          }))

          for (let v of data.formLabel) {
            if (v.model == 'mature') {
              v.option = [...v.option, ...arr]
              break
            }
          }
        }
      })
    } else if (v.keyId === 'DICT_BUDGET') {
      let a = {
        dictType: v.keyId,
      }
      getDictItemListApi(JSON.stringify(a)).then((res) => {
        if (res.status === 200) {
          let arr = res.data.result.map(v => ({
            key: v.keyName,
            value: v.keyId
          }))
          for (let v of data.formLabel) {
            if (v.model == 'amountMoney') {
              v.option = [...v.option, ...arr]
              break
            }
          }
        }
      })
    }
  })
}
getDictList()

//获取省级行政区数据
const getRegion = () => {
  getRegionApi({ criSuperiorCode: '000000' }).then((res) => {
    if (res.status === 200) {
      let arr = res.data.map(v => ({
        key: v.criName,
        value: v.criCode
      }))
      for (let v of data.formLabel) {
        if (v.model == 'provinceCode') {
          v.option = [...v.option, ...arr]
          break
        }
      }
    }
  })
}
getRegion()

//获取成果领域
const getDomain = () => {
  getDomainApi({ parentId: 0 }).then((res) => {
    if (res.status === 200) {
      let arr = res.data.map(v => ({
        key: v.keyName,
        value: v.keyId
      }))
      for (let v of data.formLabel) {
        if (v.model == 'field') {
          v.option = [...v.option, ...arr]
          break
        }
      }
    }
  })
}
getDomain()







//列筛选
const colSelect = (headerArr, type, e, currentItem) => {
  if (type === 'filter') {
    const currentData = colFilters(headerArr, e, currentItem, data.tableHeader)
    data.tableHeader = currentData
  } else {
    //全选/全取消
    data.tableHeader = headerArr
  }
}
//刷新
const refreshTable = () => {
  getAchievementList()
}
//表头功能
const userManageBtnList = (index) => {
  switch (index) {
    case 0:
      console.log('新增科研成果')
      router.push({ name: 'AddAchieve' })
      break
    case 1:
      isShowLead.value = true
      console.log('通过文件批量导入')
      break
    case 2:
      const startArr = data.currentSelectList.map(v => v.id)
      const startFunction = () => {
        const start = {
          batchType: "START",
          ids: startArr,
        }
        operateAchievementApi(JSON.stringify(start)).then(res => {
          if (res.status === 200) {
            ElMessage({
              message: res.message,
              type: 'success',
            })
            getAchievementList()
          }
        })
      }
      batchHandle(startArr, 'START', startFunction)
      break
    case 3:
      const stopArr = data.currentSelectList.map(v => v.id)
      const stopFunction = () => {
        const stop = {
          batchType: "STOP",
          ids: stopArr,
        }
        operateAchievementApi(JSON.stringify(stop)).then(res => {
          if (res.status === 200) {
            ElMessage({
              message: res.message,
              type: 'success',
            })
            getAchievementList()
          }
        })
      }
      batchHandle(stopArr, 'START', stopFunction)
      break
    case 4:
      const delArr = data.currentSelectList.map(v => v.id)
      const delFunction = () => {
        const del = {
          batchType: "DEL",
          ids: delArr,
        }
        operateAchievementApi(JSON.stringify(del)).then(res => {
          if (res.status === 200) {
            ElMessage({
              message: res.message,
              type: 'success',
            })
            getAchievementList()
          }
        })
      }
      batchHandle(delArr, 'DEL', delFunction)
      break
    default:
      break
  }
}
//勾选成果
const getSelectChange = (row) => {
  data.currentSelectList = row
}
//分页查看
const getCurrentChange = (cur) => {
  data.pagination.currentPage = cur
  getAchievementList()
}
//每页条数
const getSizeChange = (cur) => {
  data.pagination.size = cur
  getAchievementList()
}


//上传文件
const uploadFile = (data) => {
  let fd = new FormData()
  fd.append('file', data.file);
  fd.append('dataType', 'RESULT')
  uploadOtherFileApi(fd).then(res => {
    isShowLead.value = false
    ElMessage.success(res.message)
    getAchievementList()
  })
}

//下载文件
const downloadFile = () => {
  dowloadOtherFileApi({ dataType: 'RESULT' }).then(res => {
    fileDownload({
      fileSuffix: 'xlsx',
      name: '科技成果导入模板'
    }, res)
  })
}


//补充成果信息
const addResultInfo = (id) => {
  achievementDetailApi({ id }).then(res => {
    if (res.status === 200) {
      data.currentResultDetail = res.data
      data.form.assessInnovate = res.data.assessInnovate
      data.form.assessAdvanced = res.data.assessAdvanced
      data.form.assessComplex = res.data.assessComplex
      data.form.assessSample = res.data.assessSample
      data.form.assessReport = res.data.assessReport
      data.form.assessSubsidize = res.data.assessSubsidize
      data.form.assessAward = res.data.assessAward
      data.form.assessIsEconomicBenefits = res.data.assessIsEconomicBenefits
      data.form.assessEconomicBenefits = res.data.assessEconomicBenefits
      data.form.assessSocialBenefits = res.data.assessSocialBenefits
      data.form.assessApplicationEffect = res.data.assessApplicationEffect
      data.form.assessInputMoney = res.data.assessInputMoney
      data.dialogVisible = true
    }
  })
}
//确定补充
const addInfo = () => {
  let params = {
    id: data.currentResultDetail.id,
    resultTitle: data.currentResultDetail.resultTitle,
    industryNameOne: data.currentResultDetail.industryNameOne,
    industryCodeOne: data.currentResultDetail.industryCodeOne,
    industryNameTwo: data.currentResultDetail.industryNameTwo,
    industryCodeTwo: data.currentResultDetail.industryCodeTwo,
    industryNameThree: data.currentResultDetail.industryNameThree,
    industryCodeThree: data.currentResultDetail.industryCodeThree,
    resultTypeName: data.currentResultDetail.resultTypeName,
    resultTypeCode: data.currentResultDetail.resultTypeCode,
    resultProvinceName: data.currentResultDetail.resultProvinceName,
    resultProvinceCode: data.currentResultDetail.resultProvinceCode,
    resultCityName: data.currentResultDetail.resultCityName,
    resultCityCode: data.currentResultDetail.resultCityCode,
    resultAreaName: data.currentResultDetail.resultAreaName,
    resultAreaCode: data.currentResultDetail.resultAreaCode,
    detailAddress: data.currentResultDetail.detailAddress,
    resultExpirationDate: data.currentResultDetail.resultExpirationDate,
    resultCooperationName: data.currentResultDetail.resultCooperationName,
    resultCooperationCode: data.currentResultDetail.resultCooperationCode,
    resultBudgetType: data.currentResultDetail.resultBudgetType,
    resultBudget: data.currentResultDetail.resultBudget,
    resultSkillStageName: data.currentResultDetail.resultSkillStageName,
    resultSkillStageCode: data.currentResultDetail.resultSkillStageCode,
    includePatent: data.currentResultDetail.includePatent,
    patentList: data.currentResultDetail.patentList,
    resultDescribe: data.currentResultDetail.resultDescribe,
    resultTarget: data.currentResultDetail.resultTarget,
    resultCase: data.currentResultDetail.resultCase,
    resultKeyword: data.currentResultDetail.resultKeyword,
    resultProductName: data.currentResultDetail.resultProductName,
    resultPublishPerson: data.currentResultDetail.resultPublishPerson,
    resultContactPerson: data.currentResultDetail.resultContactPerson,
    resultContactPhone: data.currentResultDetail.resultContactPhone,
    isPublic: data.currentResultDetail.isPublic,
    ...data.form
  }
  let fd = new FormData()
  fd.append('form', new Blob([JSON.stringify(params)]))
  editAchievementApi(fd).then(res => {
    if (res.status === 200) {
      ElMessage({
        message: res.message,
        type: 'success',
      })
      data.dialogVisible = false
    }
  })
}
//详情
const comEvent = (type, row) => {
  sessionStorage.resultId = row.id
  if (type == 'detail') {
    router.push({ name: 'AchieveDetail', params: { id: row.id, type: "detail" } })
  }
}
//审核
const checkRow = (row) => {
  sessionStorage.resultId = row.id
  router.push({ name: 'CheckAchieve', params: { id: row.id, type: "check" } })
}
//编辑需求
const editRow = (row) => {
  sessionStorage.resultId = row.id
  if (row.valid) {
    return
  } else {
    router.push({ name: 'EditAchieve', params: { id: row.id } })
  }
}
//单个删除启用禁用
const operateRow = (row, type) => {
  if (type == 'del') {
    const delFunction = () => {
      let params = {
        batchType: 'DEL',
        ids: [row.id],
      }
      operateAchievementApi(JSON.stringify(params)).then((res) => {
        if (res.status === 200) {
          ElMessage({
            message: res.message,
            type: 'success',
          })
          getAchievementList()
        }
      })
    }
    lineHandle(row, 'del', delFunction)
  } else if (type == 'valid') {
    const validFunction = () => {
      let params = {
        batchType: row.valid ? 'STOP' : 'START',
        ids: [row.id],
      }
      operateAchievementApi(JSON.stringify(params)).then((res) => {
        if (res.status === 200) {
          ElMessage({
            message: res.message,
            type: 'success',
          })
          row.valid = !row.valid
        }
      })
    }
    lineHandle(row, 'valid', validFunction)
  }
}
//上热门
const hotRow = (row) => {
  const hotFunction = () => {
    let params = {
      batchType: row.isHot ? 'STOP_HOT' : "START_HOT",
      ids: [row.id],
    }
    operateAchievementApi(JSON.stringify(params)).then((res) => {
      if (res.status === 200) {
        ElMessage({
          message: res.message,
          type: 'success',
        })
        row.isHot = !row.isHot
      }
    })
  }
  lineHandle(row, 'isHot', hotFunction)
}
//行内编辑鼠标手型
const mouseStatus = (row, e) => {
  if (row.valid) {
    e.target.style.cursor = 'not-allowed'
  } else {
    e.target.style.cursor = 'pointer'
  }
}
</script>

<style lang="scss" scoped>
.table-button {
  display: flex;
  justify-content: flex-start;

  .btn {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-right: 10px;

    .text-left {
      margin-right: 2px;
    }
  }

  .btn:last-child {
    margin-right: 0;
  }
}

.add-info-dialog {

  .df {
    display: flex;
  }

  .ac {
    align-items: center;
  }

  .jc {
    justify-content: center;
  }

  .el-dialog__header {
    .dialog-title {
      align-items: flex-end;
      margin-bottom: 10px;

      h3 {
        margin: 0;
      }

      .tip {
        font-size: 14px;
        color: #006cba;
        margin-left: 10px;
      }
    }
  }

  .dialog-table {
    border: 1px solid #d3d4db;

    .dialog-head {
      padding-left: 20px;
      height: 40px;
      font-size: 14px;
      font-weight: 700;
      color: #606d87;
      background: #f7f8fc;
    }

    .el-form {
      padding: 10px 20px;
    }

    :deep(.el-form-item) {
      margin-bottom: 0;
      height: 34px;
    }

    :deep(.el-form-item__label) {
      width: 170px;
    }
  }

  .dialog-table:nth-child(2) {
    margin: 20px 0;
  }

  :deep(.el-dialog__body) {
    padding: 0 20px;
  }

  .dialog-footer {
    padding: 10px 0;
    text-align: center;

    .el-button {
      width: 140px;
    }
  }
}
</style>
